import { defineStore } from 'pinia'
import { EncryptStorage } from "encrypt-storage";
//需注意使用stateManagementUse
export const encryptStorage = new EncryptStorage("YM1234567890", {
  stateManagementUse: true,
});
export interface SiteConfig<T = any> {
    site_name: string
    record_number: string
    wx_img: string
    sm: string
    about: string
    logo:string,
    logo2:string,
    logo3:string,
    login_img:string,
    default_head:string,
    defalut_product_img:string,
    default_video_img:string,
    accomplish_download:string,
    progress_download:string,
    recharge:T,
    ad:T,
    download_pay_img:string,
    subscribe:T,
    agreement:T,
    login_page:T,
    download_day:number,
    is_download:number,

}

export const useSiteConfig = defineStore('siteConfig', {
    state: (): SiteConfig => {
        return {
            site_name: '',
            record_number: '',
            wx_img: '',
            sm: '',
            about: '',
            logo: '',
            logo2: '',
            logo3: '',
            login_img:'',
            default_head:'',
            defalut_product_img:'',
            default_video_img:'',
            accomplish_download:'',
            progress_download:'',
            recharge:[],
            ad:[],
            download_pay_img:'',
            subscribe:[],
            agreement:[],
            login_page:[],
            download_day:0,
            is_download:1
        }
    },
    actions: {
        dataFill(state: SiteConfig) {
            this.$state = { ...this.$state, ...state }
        },
    },
    persist: {
        enabled: true,
        key: "siteConfig", //如果需要对存储的密钥key进行命名
        storage: encryptStorage,
        // storage: localStorage, //如果不使用加密处理
        paths: ["siteConfig"],
    },
})